<?php
	require_once("function/initialize.php");
	
	if(isset($_POST["btnLogin"]))
	{
		openConnection();
		$user = trim($_POST["txtName"]);
		$pwd = trim(md5($_POST["txtPwd"]));
		if($user != "" and $pwd != "")
		{
			$found = findUser($user, $pwd);
			if($found)
			{
				login($found);
				$type=getUserType();
				if($type=="admin"){
					pageRedirect("index.php","");
				}else{
					pageRedirect("index_user.php","");
				}				
			}
			else
			{
				errorMessage("Invalid User name and Password");					
			}
		}
		else
		{
			errorMessage("User Name and Password is required!");
		}
		closeConnection();
	}
	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/mainstyle.css" rel="stylesheet" type="text/css"  media="screen"/>
<link href="css/login.css" rel="stylesheet" type="text/css"  media="screen"/>
<title>Homo | Master Page</title>

<script language="javascript" type="text/javascript">
		function clearText(field)
			{
				if (field.defaultValue == field.value) field.value = '';
				else if (field.value == '') field.value = field.defaultValue;
			}
</script>
</head>

<body>
	<div class="header">
         <?php require_once('include_layout/header.php'); ?>
    </div><!--end header -->
    	<?php 
			if(@$errors!=""){
		?>
				<div  class="msm" align="center"><?php echo  $errors?></div>
        <?php 		
			}
		?>
    <div class="center" align="center">
        <div class="login">
             <form name="frm_login" class="frm_login" action="login.php" method="post" >
             	<input type="text" class="txtName" name="txtName" value="Username" onfocus="clearText(this)" onblur="clearText(this)" /><br />
             	<input type="password" class="txtPwd" name="txtPwd" value="password" onfocus="clearText(this)" onblur="clearText(this)" /> <br />
                <input type="submit" class="btn" name="btnLogin" value=""/>                
             </form> 
        </div>
    </div><!--end center -->
    <div class="footer">
    	<?php 
			require_once('include_layout/footer.php');
		?>
    </div><!--end footer -->
</body>
</html>
